// request 是我们封装的一个网络请求库
import request from './../utils/request';
import config from './../config';
import {
    empty
} from './../utils/helper';

const url = config.service.host;

// 获取微信用户的订单列表
export function getOrderList(params, cb = function() {}) {
    request(`${url}/index/order`, params, false).then((res) => {
        cb(res)
    })
}

// 查询订单
export function queryOrder(params, cb = function() {}) {
    request(`${url}/index/queryOrder`, params).then((res) => {
        cb(res)
    })
}

// 微信支付
export function wxPayment(res, obj) {
    if (!empty(res)) {
        wx.requestPayment({
            'timeStamp': res.timeStamp,
            'nonceStr': res.nonceStr,
            'package': res.package,
            'signType': res.signType,
            'paySign': res.paySign,
            'success': function(res) {
                obj.success(res);
            },
            'fail': function(res) {
                obj.fail(res);
            },
            'complete': function(res) {
                obj.complete(res);
            },
        });
    }
}